import './index.scss';
import tpl from './index.tpl';
import CheckBox from '../check_box/index';

const checkBox = new CheckBox();

export default () => {
	return {
		name: 'purchaseBox',
		//子组件无法自己获取price，只能通过父组件传入的总价格
		tpl(price) {
			let html = tpl().replace(/{{(.*?)}}/g, (node, key) => {
				return {
					price,
					check_box: checkBox.tpl(0, 'mainCheck')
				} [key];
			});

			let oBox = document.createElement('div');
			oBox.className = 'purchase-box';
			oBox.innerHTML = html;

			return oBox;
		},
		//单击购物车商品项的 单选框按钮 打勾/不打勾 全选/不全选功能
		// onMainCheck(total) {
		// 	const oSubChecks = Array.from(document.getElementsByClassName('J_subCheck')),
		// 		oMainCheck = document.getElementsByClassName('J_mainCheck')[0],
		// 		oTotal = document.getElementsByClassName('J_totalPrice')[0];

		// 	//全选
		// 	oSubChecks.forEach((elem) => {
		// 		elem.checked = oMainCheck.checked;
		// 	});

		// 	oTotal.innerHTML = oMainCheck.checked ? total : 0;
		// }
	}
}